//
//  WBTabBarController.m
//  MyWeiBo
//
//  Created by wangneihan on 16/1/9.
//  Copyright © 2016年 wangneihan. All rights reserved.
//

#import "WBTabBarController.h"
#import "ISPHomeController.h"
#import "ISPInspirationController.h"
#import "ISPPersonalController.h"
#import "ISPProductController.h"
#import "WBTabBar.h"

@interface WBTabBarController ()

@property(nonatomic,strong) NSMutableArray *item;

@end

@implementation WBTabBarController

-(BOOL)prefersStatusBarHidden
{
    return NO;
}

-(NSMutableArray *)item
{
    if (_item == nil) {
        _item = [NSMutableArray array];
    }
    return _item;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 1. 添加控制器
    [self AddControlls];
    WBTabBar *tabBar = [[WBTabBar alloc]initWithFrame:self.tabBar.frame];
    tabBar.btnItems = self.item;
    //[self setValue:tabBar forKeyPath:@"tabBar"];
    [self.view addSubview:tabBar];
    [self.tabBar removeFromSuperview];
}

-(void)AddControlls
{
    //1. Home
    ISPHomeController *homeController = [[ISPHomeController alloc]init];
    [self makeSubControl:homeController title:@"首页" Img:[UIImage imageNamed:@"tabbar_home"] badgeValue:@"10" selectImg:[UIImage imageNamed:@"tabbar_home_selected"]];
    
    ISPInspirationController *discoverController = [[ISPInspirationController alloc]init];
    [self makeSubControl:discoverController title:@"发现" Img:[UIImage imageNamed:@"tabbar_discover"] badgeValue:@"10" selectImg:[UIImage imageNamed:@"tabbar_discover_selected"]];
    
    ISPProductController *messageController = [[ISPProductController alloc]init];
    [self makeSubControl:messageController title:@"消息" Img:[UIImage imageNamed:@"tabbar_message_center"] badgeValue:@"10" selectImg:[UIImage imageNamed:@"tabbar_message_center_selected"]];
    
    ISPPersonalController *profileController = [[ISPPersonalController alloc]init];
    [self makeSubControl:profileController title:@"我" Img:[UIImage imageNamed:@"tabbar_profile"] badgeValue:@"10" selectImg:[UIImage imageNamed:@"tabbar_profile_selected"]];
    
}

-(void)makeSubControl:(UIViewController *)controller  title:(NSString *)title Img:(UIImage *)image badgeValue:(NSString *) badge selectImg:(UIImage *)selectImg
{
    controller.tabBarItem.title = title;
    controller.tabBarItem.image = image;
    controller.tabBarItem.badgeValue = badge;
    controller.tabBarItem.selectedImage = [selectImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    controller.navigationItem.title = title;
    
    [self.item addObject:controller.tabBarItem];
    //NSLog(@"%ld",self.item.count);
    UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:controller];
    [self addChildViewController:navC];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
